<%
DIRECTIVE SAFE_OUTPUT_OPEN;
var headContent = {
include("/pages/template/head.html"){}
%>
<script type="text/javascript">
	$(function(){
			// 初始化，设置被选中
			var bindProductinfo = $("#bindProductinfo").val().split(",");
			for(var i = 0 ; i < bindProductinfo.length ; i++){
				if(bindProductinfo[i]!=''){ 
					$("[id='productvasids_"+bindProductinfo[i]+"']").attr("checked",true);
				} 
			}
			
		});

    var oper = {
        saveBind:function(){
           var productinfoids = "";
           var level  = "";
           var flag = true;
			$('input[name="checkedids"]:checked').each(function() {
				productinfoids += $(this).val() + '-';
				level = $("input[name='"+this.id+"']").val() 
				if(level ==""){
					flag = false;
					return;
				}
				productinfoids += level +",";
			});
			if(!flag){
				BootstrapDialog.alert("关联产品存在优先级未设置");
			}else{
				if (productinfoids != "") {
					productinfoids = productinfoids.substring(0, productinfoids.length - 1);
				}
			var url = 'system/productvas/saveBind/'+productinfoids;
            form1.action = url;
            form1.submit();
            return true;
			}
			
        },
		productvaslist : function() {
			var form = $("#productvasForm");
			var queryProductName = $("#queryProductinfoName").val();
			var url = 'system/productvas/bindProductinfo?productName='
					+ queryProductName;
			form.action = url;
			form.submit();
		}
    };

</script>

<%
};
var bodyContent = {
%>
<form name="form1" id = "productvasForm" action="" method="post"  class="form-inline" role="form">
		<input name="ids" type="hidden" value="${ids}" >
		
		<input id="bindProductinfo" name="bindProductinfo" type="hidden" value="${bindProductinfo!''}" >
	<div class="tableSearch">
		<%  //查询列表 %>
		<div class="form-group" style="width: 50%; display: inline-block">
			<input class="form-control" id = "queryProductinfoName" type="text" name="productName" value="${productName!''}"
				   placeholder="请输入产品名称"  />
		</div>
			<button  type="button" class="btn btn-default" onclick="resetForm();">
				<span class="glyphicon glyphicon-refresh"></span> 重 置
			</button>
			<button type="button" class="btn btn-default" onclick="oper.productvaslist();" name="search">
				<span class="glyphicon glyphicon-search"></span> 查 询
			</button>
			<button class="btn btn-default" onclick="oper.saveBind();return false;"></span> 保 存</button>
	</div>
	<!-- 数据列表 -->
	<table class="table table-striped table-bordered table-hover">
		<thead>
		<tr>
			<th>序号</th>
			<%  // 列表头部 %>
			<th name="ids" style = "width:5%"> </th>
			<th name="productName" style = "width:45%" >供应商产品名称</th>
			<th name="discountPrice" >折后价格</th>
			<th name="discountPrice" >设置优先级</th>
		</tr>
		</thead>
		<tbody>
		<% for(item in page){ %>
		<tr>
			<td>${itemLP.index }</td>
			<td>
				<input type="checkbox" id="productvasids_${item.ids}" name="checkedids" value="${item.ids}" />
			</td>
			<%  // 列表内容 %>
			<td>${item.productName}</td>
			<td>${item.discountPrice}</td>
			<td>
				<input type="text" name="productvasids_${item.ids}" value="1" style="width:100px;" class="form-control" />
			</td>
		</tr>
		<% } %>
		</tbody>
	</table>
</form>
<%}; %>

<% layout("/pages/template/_layout.html",{head:headContent,body:bodyContent}){ %>
DIRECTIVE SAFE_OUTPUT_CLOSE;
<%} %>